package com.test.kotlin02

fun main() {
    val total:Int = "Mississippi".count();
    println(total)

    val totals:Int =  "Mississippi".count({ letter->  //匿名函数
        letter =='s'
    })

    println(totals)


    //变量的类型是一个匿名函数
    val blessingFunction:()->String
    blessingFunction = {
        val holiday = "New Year."  //
        "Happy $holiday"        //匿名函数，返回隐式返回
    }

    println(blessingFunction())


    val blessingFunction2:()->String = {
        val holiday = "New Year."  //
        "Happy $holiday"        //匿名函数，返回隐式返回
    }

    println(blessingFunction2())



    //变量的类型是一个匿名函数,带参数，参数类型为String, 名字为name
    val blessingFunction3:(String )->String = {  name ->
        val holiday = "New Year."  //
        "$name, Happy $holiday"        //匿名函数，返回隐式返回
    }

    println(blessingFunction3("lwb"))



    //变量的类型是一个匿名函数,带参数，参数类It型为String, it关键字
    val blessingFunctionIt:(String )->String = {  it ->
        val holiday = "New Year. --> It "  //
        "$it, Happy $holiday"        //匿名函数，返回隐式返回
    }

    println(blessingFunctionIt("lwb"))


    //变量的类型是一个匿名函数,带参数，参数类It型为String, it关键字
    val blessingFunctionStringInt:(String ,Int)->String = {  name,year ->
        val holiday = "New Year. --> It "  //
        "$name, Happy $holiday $year"        //匿名函数，返回隐式返回
    }

    println(blessingFunctionStringInt("lwb",2027))


    //变量的类型是一个匿名函数,带参数，参数类It型为String, it关键字
    val blessingFunctionNoParams:(String,Int) ->String = {  name:String,year:Int ->
        val holiday = "New Year. --> It "  //
        "$name, Happy $holiday $year"        //匿名函数，返回隐式返回
    }

    println(blessingFunctionNoParams("lwb",2027))


}